﻿/*
 * Create By:Jeff Yuan
 * Create Time : 2009-03-16 11:30
 * 
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Jumpton.SFA.Server.Entity;
using Jumpton.Persistent;
using Jumpton.SFA.Server.BusinessRule;
using Jumpton.Data;
namespace Jumpton.SFA.Server.BusinessRule.System
{
    public class EventLogTypesManager 
    {
        #region IBusinessLogic 实现

        #region 保存
       
        public void Save(EventLogTypes eventlogtype)
        {
           
            if (eventlogtype != null)
            {
                try
                {
                    //if (eventlogtype.State == DataRowState.Added)
                    //    eventlogtype.LogTypeKey = Common.KeyFactoryManager.GetCurrentValue("LogTypeKey", 0);


                    EventLogTypes objx = ObjectRow.Load(typeof(EventLogTypes), string.Format("LogTypeKey='{0}'", eventlogtype.LogTypeKey)) as EventLogTypes;
                    if (objx != null)
                    {
                        throw new Exception("存在相同事件类型");
                    }
                    eventlogtype.Save();

                }
                catch (Exception error)
                {
                    throw new Exception(error.Message);
                }
            }

        }
        #endregion

       

        #region 获得唯一性代码数据
       
        public EventLogTypes LoadByCode(string Code)
        {
            return (EventLogTypes)ObjectRow.Load(typeof(EventLogTypes), "LogTypeKey='" + Code.ToString() + "'");
        }
        #endregion

        #region 获得一组数据
      
        public ObjectTable LoadWithCondition(string Condition)
        {
            return new ObjectTable(typeof(EventLogTypes), Condition.ToString());
        }
        #endregion

        #endregion

        #region 是否存在同名日志类型
        /// <summary>
        /// 是否存在同名日志类型
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static bool IsExistsLogTypeKey(string LogTypeKey)
        {
            EventLogTypes eventlogtype = (EventLogTypes)ObjectRow.Load(typeof(EventLogTypes), "LogTypeKey='" + LogTypeKey + "'");
            if (eventlogtype != null)
                return true;
            else
                return false;

        }
        #endregion

        #region 获得所有数据
        /// <summary>
        /// 获得所有数据
        /// </summary>
        /// <returns></returns>
        public ObjectTable GetAll()
        {
            return LoadWithCondition("");
        }
        #endregion
    }
}
